// components/navigation2/navigation2.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        //获取系统信息可以直接赋值
        statusBarHeight: wx.getSystemInfoSync().statusBarHeight,
        wxBarHeight: wx.getSystemInfoSync().statusBarHeight + 40,

        // 一定要在attached里赋值，否则真机测试赋值不了！
        userAquariumArray: [],
        curIndex: 0
    },

    lifetimes: {
        attached() {
            this.setData({
                curIndex: parseInt(wx.getStorageSync('curIndex')),
                userAquariumArray: wx.getStorageSync('userAquariumArray')
            })
            // console.log(wx.getStorageSync('userAquariumArray'))
            // console.log("本地存储的curIndex:" +wx.getStorageSync('curIndex'))
            // console.log(this.data.userAquariumArray)
        }
    },


    /**
     * 组件的方法列表
     */
    methods: {

        //重新加载当前页面
            updatePage:function() {
            console.log("页面更新！")
            var pages = getCurrentPages()    //获取加载的页面
            var currentPage = pages[pages.length - 1]    //获取当前页面的对象
            var curUrl = currentPage.route    //当前页面url
            curUrl = '../../' + curUrl
            console.log(curUrl)
            wx.reLaunch({
                url: curUrl

            })
        },


        last() {

            if (this.data.curIndex == 0) {
                this.setData({
                    curIndex: this.data.userAquariumArray.length - 1
                })

            } else {
                this.setData({
                    curIndex: this.data.curIndex - 1
                })
            }
            wx.setStorageSync('curIndex', this.data.curIndex)
            // console.log("本地存储的curIndex:" +wx.getStorageSync('curIndex'))
            // console.log("当前窗口的curIndex:"+this.data.curIndex)

            //重新加载当前页面
            this.updatePage()
        },
        next() {

            if (this.data.curIndex == this.data.userAquariumArray.length - 1) {
                this.setData({
                    curIndex: 0
                })
            } else {
                this.setData({
                    curIndex: this.data.curIndex + 1
                })
            }
            wx.setStorageSync('curIndex', this.data.curIndex)
            // console.log("本地存储的curIndex:" +wx.getStorageSync('curIndex')+"类型："+typeof(wx.getStorageSync('curIndex')))
            // console.log("当前窗口的curIndex:"+this.data.curIndex)


            //重新加载当前页面
            this.updatePage()

        },

        bindPickerChange: function (e) {
            this.setData({
                curIndex: parseInt(e.detail.value)
            })
            wx.setStorageSync('curIndex', this.data.curIndex)
            // console.log("本地存储的curIndex:" +wx.getStorageSync('curIndex'))
            // console.log("当前窗口的curIndex:"+this.data.curIndex)

            //重新加载当前页面
            this.updatePage()

        },

    }
})
